﻿namespace Example.Runtime.Serialization
{
    using System.IO;
    using System.Runtime.Serialization.Formatters.Soap;

    public static class SoapSerializer
    {
        public static string ToString(object value)
        {
            string buffer = null;

            if (null != value)
            {
                using (var stream = new MemoryStream())
                {
                    new SoapFormatter().Serialize(stream, value);
                    stream.Seek(0, SeekOrigin.Begin);

                    using (var reader = new StreamReader(stream))
                    {
                        buffer = reader.ReadToEnd();
                    }
                }
            }

            return buffer;
        }
    }
}